<?
class Partition {
    static protected $cmd_udev = '/sbin/udevadm info -q property -n ';
    var $device;
    var $garbirus_mountpoint='/media/garbirus';

    public static function isPartition($dev){
        $dtype=explode('=', exec(self::$cmd_udev.$dev.'|grep DEVTYPE='));
        if ($dtype[1] == 'partition'){
            return true;
        } else {
            return false;
        }
    }

    function getSize(){
        $size=0;
        $size=explode('=', exec(self::$cmd_udev.$this->device.'|grep UDISKS_PARTITION_SIZE='));
        $size=(int)$size[1];
        return $size;
    }

    function getLabel(){
        $label='undefined';
        $label=explode('=', exec(self::$cmd_udev.$this->device.'|grep ID_FS_LABEL='));
        $label=$label[1];
        return $label;
    }

    function isMounted(){
        //
        // True: $this->device is mounted
        // False: $this->device is not mounted
        //
        $mounted=exec("grep '".$this->device." ' /proc/mounts && echo $?");
        $mounted=(int)$mounted;

        if ($mounted == 0){
            return True;
        } else {
            return False;
        }
    }

    function getMountpoint(){
        //
        // returns path where '$this->device' is mounted: /mnt
        //
        $mountpoint=exec("grep '".$this->device." ' /proc/mounts |cut -d' ' -f2");
        return $mountpoint;
    }

    function mount(){
        $result=exec("/usr/bin/sudo /bin/mount ".$this->device." ".$garbirus_mountpoint);
    }

    function umount(){
        $result=exec("/usr/bin/sudo /bin/umount ".$this->device);
    }

    function Partition($device) {
        $dtype=explode('=', exec(self::$cmd_udev.$this->device.'|grep DEVTYPE='));
        if ($dtype[1] == 'partition'){
            $this->device=$device;
            return true;
        } else {
            return false;
        }
    }
}
?>
